package com.example.mobile2021606170hsy0406homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Main5Activity extends AppCompatActivity {

    private TextView tvMainTitle;
    private TextView tvMainDecode;
    private TextView tvMainAskfor;
    private TextView tvMainFahrenheit;
    private EditText adtTxtMainFahrenheit;
    private Button btMainResult;
    private EditText edtTxtMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);
        initView();
    }

    private void initView() {
        tvMainTitle = findViewById(R.id.tv_main_title);
        tvMainDecode = findViewById(R.id.tv_main_decode);
        tvMainAskfor = findViewById(R.id.tv_main_askfor);
        tvMainFahrenheit = findViewById(R.id.tv_main_fahrenheit);
        adtTxtMainFahrenheit = findViewById(R.id.adtTxt_main_fahrenheit);
        btMainResult = findViewById(R.id.bt_main_result);
        edtTxtMainResult = findViewById(R.id.edtTxt_main_result);
    }
    public  void resultonClik(View view){
        String num =adtTxtMainFahrenheit.getText().toString();
        if(num.length()==0) {
            Toast.makeText(Main5Activity.this, "请输入度数",Toast.LENGTH_SHORT).show();
        }else {
            double f=Double.parseDouble(num);
            double c=0;
            c=5*(f-32)/9;
            String str =String.format("%.2f,c");
            edtTxtMainResult.setText(str);
            }
        }

    }
